package com.ssm.common.tool;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

/**
 * Author:      Dante Lee
 * Time:        2015-11-05 09:59 AM
 * Description: 自定义公共方法
 */
public class Deal {
	
	public String retString(Object obj) {
		if (obj == null)
			return "";
		else
			return String.valueOf(obj);
	}
	
	public String delNull(Object obj) {
		if (obj == null||"".equals(obj))
			return "无";
		else
			return String.valueOf(obj);
	}
	
	/**
	 * 按照指定格式设置并返回date
	 * 
	 * @param int s
	 *       
	 * @return String
	 */
	public String getdate(int s){
		SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMdd"); //设置时间格式
		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.DATE, s);
		return sdf.format(cal.getTime());
	}
	
	public String getDate() {
		Date now = new Date();
		DateFormat formatter = null;
		formatter = new SimpleDateFormat("yyyyMMddHHmmss", Locale.CHINA);
		String strDte = formatter.format(now);
		return strDte;
	}
	
	public String dealDateDP(String s){
		int length = s.length();
		int index = s.indexOf(":");
		String h = s.substring(11, index);
		String h_sign = s.substring(length-2, length);
		if("AM".equals(h_sign)){
			if(Integer.parseInt(h)<10){
				h = "0"+h;
			}
		}else{
			h = String.valueOf(Integer.parseInt(h)+12);
		}
		String m = s.substring(index+1, index+3);
		return s.substring(6, 10)+s.substring(0, 2)+s.substring(3, 5)+h+m+"00";
	}
}
